﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;
public partial class Supervise_TraSubmiBidPrice_ZBZX : System.Web.UI.Page
{
    
    static string strarea ="";
    static int m = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumSupervise);
        if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))
        {
            HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
             if (_Account.DWName.IndexOf("药品招标办") > -1)
            {
                switch (_Account.UserCode)
                {
                    case "ZBB001": //郑州市药品招标办
                        strarea = "云南1";
                        m = 14;
                        break;
                    case "ZBB002": //开封市药品招标办
                        strarea = "云南2";
                        m = 15;
                        break;
                    case "ZBB003": //洛阳市药品招标办
                        strarea = "云南3";
                        m = 16;
                        break;
                    case "ZBB004": //安阳市药品招标办
                        strarea = "云南4";
                        m = 17;
                        break;
                    case "ZBB005": //濮阳市药品招标办
                        strarea = "云南5";
                        m = 18;
                        break;
                    case "ZBB006": //鹤壁市药品招标办
                        strarea = "云南6";
                        m = 19;
                        break;
                    case "ZBB007": //新乡市药品招标办
                        strarea = "云南7";
                        m = 20;
                        break;
                    case "ZBB008": //焦作市药品招标办
                        strarea = "云南8";
                        m = 21;
                        break;
                    case "ZBB009": //济源市药品招标办
                        strarea = "云南9";
                        m = 22;
                        break;
                    case "ZBB010": //三门峡市药品招标办
                        strarea = "云南10";
                        m = 23;
                        break;
                    case "ZBB011": //南阳市药品招标办
                        strarea = "云南11";
                        m = 24;
                        break;
                    case "ZBB012": //平顶山市药品招标办
                        strarea = "云南12";
                        m = 25;
                        break;
                    case "ZBB013": //信阳市药品招标办
                        strarea = "云南13";
                        m = 26;
                        break;
                    case "ZBB014": //驻马店市药品招标办
                        strarea = "云南14";
                        m = 27;
                        break;
                    case "ZBB015": //许昌市药品招标办
                        strarea = "云南15";
                        m = 28;
                        break;
                    case "ZBB016": //漯河市药品招标办
                        strarea = "云南16";
                        m = 29;
                        break;
                    case "ZBB017": //商丘市药品招标办
                        strarea = "云南17";
                        m = 30;
                        break;
                    case "ZBB018": //周口市药品招标办
                        strarea = "云南18";
                        m = 31;
                        break;   
                }
                reload();
            }
            else
            {
                Response.Write("<script>alert('不是招标办，不需要输入！');</script>;");
                Button1.Enabled = false; Button3.Enabled = false;
            }
          
        }
            
        
    }
    private void reload()
    {
        for (int i = 14; i < 32; i++)
        {

            GridView1.Columns[i].Visible = true;
        }
        showGridView();
        for (int i = 14; i < 32; i++)
        {

            GridView1.Columns[i].Visible = false;
        }
    }
    public void showGridView()
    {
        string strConditions;
        strConditions = fctConditions();
        Db db = new Db();
        DbPage dbPage = new DbPage(db);
        dbPage.Table = "zbgs8";
        dbPage.Key = "goodsid";
        dbPage.Where = strConditions;                        //
        dbPage.SelectField = " 标段,goodsid,productname,medicinemodel,outlookc,unit,factor,cengci,companyname_sc,companyname_tb,最高零售价,最高零售价出处,bidprice,云南1,云南2,云南3,云南4,云南5,云南6,云南7,云南8,云南9,云南10,云南11,云南12,云南13,云南14,云南15,云南16,云南17,云南18";                             //可以不设，默认为“*”

        dbPage.PageIndex = SysFun.ToInt(Request["CurrentlyPageIndex"]);          //要显示第几页   
        dbPage.PageSize = 20;                                                //Request.QueryString["PS"]);
        dbPage.OrderBy = "标段,productname,goodsid";
        System.Data.IDataReader dr = dbPage.ExecuteReader(60);
        GridView1.DataSource = dr;
        GridView1.DataBind();
        dr.Close();
        dr.Dispose();
        db.Close();
        dbPage.Db.Close();
        db.Close();
        this.DbPageFlip1.DbPage = dbPage;//将数据传给控键
        

    }

    public string fctConditions()
    {
        string  ProductName, NameTB, NameSC, Goodsid="";

        ProductName = txtProductName.Text.Trim();
        NameTB = txtNameTB.Text.Trim();

        NameSC = txtNameSC.Text.Trim();

        if (SysFun.IsNumeric(goodsidtext.Text))
        {
            Goodsid = SysFun.ToLong(goodsidtext.Text).ToString();
        }
        string strtemp = "";
        strtemp = " isbid1=1 And";

        if (ProductName != "")
        {
            strtemp += " ProductName like '%" + ProductName + "%' And";
        }
        if (NameTB != "")
        {
            strtemp += " companyname_tb like '%" + NameTB + "%' And";
        }

        if (NameSC != "")
        {
            strtemp += " companyname_sc like '%" + NameSC + "%' And";
        }

        if (Goodsid != "")
        {
            strtemp += " Goodsid like '%" + Goodsid + "%' And";
        }
        if (strtemp != "")
        {
            strtemp = "  " + strtemp.Substring(0, strtemp.Length - 3);
        }

        return strtemp;

    }


    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
         
            if ((e.Row.Cells[m].Text == "") || (e.Row.Cells[m].Text == "&nbsp;"))
            {
                e.Row.Cells[13].Text = "<input type='hidden' name='buyplangoodsid' value='" + e.Row.Cells[1].Text + "' /><input type='text' size=8  name='txtBidPrice' onblur=\"javascript:if(!/^[0-9]+(\\.[0-9]{1,2})?$/.test(this.value)){alert('流水号" + e.Row.Cells[1].Text + "请输入正确的数量！');this.value='0.0'}\" NumericOnly='GoodsNum' NotNull='GoodsNum'  value='0.0' >";
            }
            else
            {
                e.Row.Cells[13].Text = "<input type='hidden' name='buyplangoodsid' value='" + e.Row.Cells[1].Text + "' /><input type='text' size=8  name='txtBidPrice' onblur=\"javascript:if(!/^[0-9]+(\\.[0-9]{1,2})?$/.test(this.value)){alert('流水号" + e.Row.Cells[1].Text + "请输入正确的数量！');this.value='" + e.Row.Cells[m].Text + "'}\" NumericOnly='GoodsNum' NotNull='GoodsNum'  value='" + e.Row.Cells[m].Text + "' >";
            }
           
        }
    }

    protected void Button3_Click(object sender, EventArgs e)
    {
        string strgoodsid = "", strprice = "", strSql="";
        strgoodsid =SysFun.IsSQL( SysFun.ToTrim(Request.Form["buyplangoodsid"]));
        strprice = Request.Form["txtBidPrice"];
        string[] SGID = strgoodsid.Length == 0 ? new string[] { "" } : strgoodsid.Substring(0).Split(new char[] { ',' });
        //08.12 增加一个判断 strprice 是否为null
        if (strprice == null)
            strprice = "";

        string[] TPrice = strprice.Length == 0 ? new string[] { "" } : strprice.Substring(0).Split(new char[] { ',' });
        for (int i = 0; i < SGID.Length; i++)
        {
            if (TPrice[i].ToString()!="0.0")
            {
                strSql += "@" + "update zbgs8 set " + strarea +"=" + TPrice[i] + " where goodsid=" + SGID[i].ToString();
            }
        }
        if ((strSql.Length > 0))
        {
            Db db = new Db();
            db.ExecuteTransaction(strSql.Substring(1).Split(new char[] { '@' }), 30);
            db.Close();
            HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
            HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "更新", "zbgs8", strSql, "../Supervise/TraSubmiBidPrice_ZBZX.aspx");
            Response.Write("<script>alert('数据保存成功！');</script>");
            reload();
        }
    }

   
}
